package com.project.KafkaRoute.executor;

import com.project.MessageRoute.executor.PushBinder;
import com.project.MessageRoute.executor.PushConsumer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class KafkaPushBinder implements PushBinder {

    public static List<PushConsumer> consumers = new ArrayList<>();

    @Value("${kafka.servers:}")
    private String servers;

    @Value("${kafka.reset:}")
    private String reset;

    @Value("${kafka.poll:}")
    private Long poll;

    @Autowired
    private KafkaListenerConsumer kafkaListenerConsumer;

    @Override
    public PushConsumer bind(String name) {
        PushConsumer push = new KafkaPushConsumer(name, servers, reset, poll, (v)->kafkaListenerConsumer.consumeMessage(v));
        KafkaPushBinder.consumers.add(push);
        return push;
    }

}
